package com.fgr.service.Impl;

import com.fgr.beans.Admin;
import com.fgr.mapper.AdminMapper;
import com.fgr.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminMapper adminMapper;

    @Override
    public List<Admin> allAdmin() {
        List<Admin> admins = adminMapper.allAdmin();
        return admins;
    }

    @Override
    public Admin findAdminById(Integer glId) {
        Admin animal = adminMapper.findAdminById(glId);
        return animal;
    }

    @Override
    public Admin findAdminByUsername(String glUsername) {
        Admin admin = adminMapper.findAdminByUsername(glUsername);
        return admin;
    }

    @Override
    public String AdminLogin(Admin admin, HttpSession httpSession) {
        Admin admin1 = adminMapper.AdminLogin(admin);
        httpSession.setAttribute("AdminLogin",admin1);
        if (admin1!=null){
            return "SUCCESS";
        }else {
            return "ERRO";
        }
    }

    @Override
    public String AddAdmin(Admin admin) {
        Admin admin1 = adminMapper.findAdminByUsername(admin.getGlUsername());
        if (admin1!=null){
            return "HAVE";
        }else {
            Integer integer = adminMapper.AddAdmin(admin);
            if (integer>0){
                return "SUCCESS";
            }else {
                return "ERRO";
            }
        }
    }

    @Override
    public String UpdateAdmin(Admin admin) {
        Integer integer = adminMapper.UpdateAdmin(admin);
        if (integer>0){
            return "SUCCESS";
        }else {
            return "ERRO";
        }    }

    @Override
    public String DeleteAdmin(Integer glId) {
        Integer integer = adminMapper.DeleteAdmin(glId);
        if (integer>0){
            return "SUCCESS";
        }else {
            return "ERRO";
        }
    }
}
